package com.imodia.checkoo.service.impl;

import org.springframework.stereotype.Service;

import com.hsq.commons.util.db.GenericIbatisDao;
import com.hsq.commons.util.db.PageBean;
import com.hsq.commons.util.db.PageResult;
import com.hsq.commons.util.db.annotation.SqlSpace;
import com.imodia.checkoo.bean.CmsJoinJobBean;
import com.imodia.checkoo.service.CmsJoinJobService;

@SqlSpace(spaceName="cmsjoinjob")
@Service("cmsJoinJobService")
public class CmsJoinJobServiceImpl 
	extends GenericIbatisDao<CmsJoinJobBean, Integer> implements
	CmsJoinJobService {

	
	public int updateStatus(int id,int status){
		String sql = "update cms_join_job set status = "+status+" where id ="+id;
		return super.getSqlDao().update(sql);
	}
	
	public int updateStatus2(int id,int status){
		String sql = "update cms_join_job set status = "+status+" where id ="+id+" and status = -1 ";
		return super.getSqlDao().update(sql);
	}
	
	
	
	public PageResult<CmsJoinJobBean> queryForPageBySql(PageBean page,CmsJoinJobBean obj){
		String sql = "select j.*,d.cn_name as area_name from cms_join_job j left join  cms_data_dictionary d on j.area_id = d.id and parent_id = 9 where 1=1 ";
		
		if(obj!=null && obj.getJobId()!=null && obj.getJobId()>0){
			sql += " and j.job_id = "+obj.getJobId();
		}
		if(obj!=null && obj.getWorkName()!=null && obj.getWorkName().trim().length()>0){
			sql += " and j.work_name like '%"+obj.getWorkName()+"%'";
		}
		if(obj!=null && obj.getCnName()!=null && obj.getCnName().trim().length()>0){
			sql += " and j.cn_name like '%"+obj.getCnName().trim()+"%'";
		}
		if(obj!=null && obj.getStatus()!=-1){
			sql += " and j.status = "+ obj.getStatus();
		}
		if(obj!=null && obj.getAreaId()!=null &&  obj.getAreaId()>0){
			sql += " and j.area_id = "+ obj.getAreaId();
		}
		
		sql += " order by j.id desc ";
		return super.getSqlDao().page(sql,CmsJoinJobBean.class,page);
	}

	
}